package com.frame.auth.security.config;

import com.frame.auth.security.service.AuthClientDetailsService;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices;
import org.springframework.security.oauth2.provider.token.DefaultTokenServices;

import javax.annotation.Resource;

/**
 * @auther zhangwj
 * @date 2021/3/11 上午10:56
 */
@Configuration
public class AuthServerTokenConfig {

    @Resource
    private AuthClientDetailsService authClientDetailsService;

    @Resource
    private TokenStoreConfig tokenStoreConfig;

    @Resource
    private TokenEnhancerConfig tokenEnhancerConfig;

    public AuthorizationServerTokenServices getAuthServerToken() {
        // 配置tokenServices参数
        DefaultTokenServices service = new DefaultTokenServices();
        //客户端详情服务
        service.setClientDetailsService(authClientDetailsService);
        //支持刷新令牌
        service.setSupportRefreshToken(true);
        //令牌存储,把access_token和refresh_token保存到数据库
        service.setTokenStore(tokenStoreConfig.getTokenStore());
        service.setTokenEnhancer(tokenEnhancerConfig);
        return service;
    }
}
